<template>
	<view>
		<view style="position:fixed; right: 3vh; top: 13vh; z-index: 999; width:100px; height: 40px;">
			<u-button type='primary' :plain="true" @click="show=!show">图例
			</u-button>
		</view>
		
		<view style="position:fixed; left: 3vh; top: 8vh; z-index: 999; width:300px; height: 12px;">
			<text style="font-size: 14px; background-color: red; color: #ecf5ff;" v-if="isInsert">沿缆线方向，从后向前，点击资源点连续插入</text>
		</view>
		
		<view style="position:fixed; left: 3vh; top: 2vh; z-index: 999; width:300px; height: 20px;">
			<u-search v-model="keyword" :show-action="false" @change="searchlist" placeholder="多个关键字用空格隔开" bgColor="#FFFFFF"
				@focus="onfocus" :clearabled="false"></u-search>
		</view>
		<view  style="position:fixed ;left: 3vh;top: 13vh;z-index: 999;width: 120px; background-color: white; border: 1px solid #3c9cff; border-radius: 2px;" v-if="selectName || errorName " @click="showSelect">
			<view v-if="selectName!= ''">
				<u--text :text='"测试点:" + selectName' size='13' color='#3c9cff'></u--text>
			</view>
			<view  v-if="errorName!= ''">
				<u--text :text='"故障点:" + errorName' size='13' color='#3c9cff'></u--text>
			</view>
		</view>
		<view style="position:fixed ;right: 3vh;top: 21vh;z-index: 999;width: 100px;">
			<u-button type='primary' :plain="true" v-if='islocated' @click="toggleSelect">添加设施
			</u-button>
		</view>
		<view style="position:fixed ;right: 3vh;top: 29vh;z-index: 999;width: 100px;">
			<u-button type='primary' :plain="true" v-if='selectId || errorId' @click="clearChoose">清空点选择
			</u-button>
		</view>
		<view style="position:fixed ;right: 3vh;top: 29vh;z-index: 999;width: 100px;">
			<u-button type='primary' :plain="true" v-if='isSingle' @click="exittoSingle">取消单独显示
			</u-button>
		</view>
		<view style="position:fixed ;right: 3vh;top: 37vh;z-index: 999;width: 100px;">
			<u-button type='primary' :plain="true" v-if='isInsert' @click="exitclickinsert">关闭点击插入
			</u-button>
		</view>
		<view style="z-index: 999; position:fixed; right: 3vh; top: 88vh; background-color: aliceblue;"
			v-show="!isloading">
			<u-image src="https://project.gxrunxiang.com/cdn/localize.png" width="35px" height="35px"
				@click="setLocation"></u-image>
		</view>
		<view style="z-index: 999; position:fixed; right: 3vh; top: 88vh; " v-show="isloading">
			<u-loading-icon></u-loading-icon>
		</view>
		
		<u-modal :show="showselect"  @confirm="toSelect" :closeOnClickOverlay="true"
				@close="showselect = false">
			<u-form labelPosition='top'  :model="fault" layout="horizontal"
			:labelCol="{span:7}" :wrapperCol="{span: 13, offset: 0}" :rules="rules" ref="uForm">
				<u-form-item label="测试点" name="City">
					<u--input v-model="selectName" :disabled="true"/>
				</u-form-item>
				<u-form-item label="故障点" name="District">
					<u--input v-model="errorName" :disabled="true"/>
				</u-form-item>
				<u-form-item label="故障距离(M)" name="Distance">
					<u-input allow-half v-model="fault.Distance"  @change='inputVal'/>
				</u-form-item>
			</u-form>
		</u-modal>
		
		<map id="maps" style="width: 100%; height: 99vh;" :latitude="latitude" :longitude="longitude" :markers="markers"
			:scale="scale" @markertap="clickMarker"  :enable-satellite="isimage" 
			:show-scale="true" :polyline="polyline" @regionchange="toRegionChange" @polylinetap="clickLine" @tap="clickmap">
			<view>
				<div class="center">
					<u-button type='primary' v-if="isselect" style="z-index: 999;width: 60px;font-size: 15px;"
						@click="inselect">选定
					</u-button>
				</div>
				<image class="center1" v-if="isselect" src='https://project.gxrunxiang.com/cdn/location.png'
					style="width:50px;height: 50px;">
				</image>
			</view>
		</map>

		<image v-if="isimage" style="position:fixed ;right: 3vh;top: 5vh;z-index: 999;width: 40px;height: 40px;"
			@click="toggleimg" src='https://project.gxrunxiang.com/cdn/vec.jpg'></image>
		<image v-if="!isimage" style="position:fixed ;right: 3vh;top: 5vh;z-index: 999;width: 40px;height: 40px"
			@click="toggleimg" src='https://project.gxrunxiang.com/cdn/img.jpg'></image>
			
		<u-modal :show="showloading" title="加载中" :showConfirmButton="false">
			<u-loading-icon text="加载中" textSize="18"></u-loading-icon>
		</u-modal>
			
		<u-popup :show="seachshow" :round="20" mode="bottom" :closeable="true" :overlay="false" :safeAreaInsetTop="true"
			@close="seachshow = false">
			<u-collapse :value="['1']">
				<u-text :text="message"></u-text>
				<u-collapse-item title="节点" name="1">
					<u-list height="190px" v-if="seachlist != false || status == 'loading'">
						<u-list-item v-for="(item,index) in seachlist" :key="index" style="margin-top:10px;">
							<u-cell :title="(index+1)+'、'+ item.Name" :label="'类型:' + item.Type + ' 市:' + item.City + ' 县:' + item.District +' 地址:' + item.Addr" :name="item.Id">
								<view slot="right-icon">
									<u-button type="primary" @click.native.stop="tonode(item)">定位</u-button>
								</view>
							</u-cell>
						</u-list-item>
					</u-list>
					<view style="height: 190px;" v-else>
						<u-empty mode="search" height="500px">
						</u-empty>
					</view>
				</u-collapse-item>
				<u-collapse-item title="缆线" name="1">
					<u-list height="200px" v-if="seachline != false || status == 'loading'">
						<u-list-item v-for="(item,index) in seachline" :key="index" style="margin-top:10px;">
							<u-cell :title="(index+1)+'、'+ item.Name"
								:label="'类型:' + item.Ftype + ' 长度:' + item.Length + ' 芯数:' + item.Num" :name="item.Id">
								<view slot="right-icon">
									<u-button type="primary" @click.native.stop="tonode(item)"
										v-if="item.Coordinate">定位</u-button>
									<u-button type="error" @click.native.stop="showNLLine(item.Id)"
										v-if="!item.Coordinate">未连接</u-button>
								</view>
							</u-cell>
						</u-list-item>
					</u-list>
					<view style="height: 200px;" v-else>
						<u-empty mode="search" height="500px">
						</u-empty>
					</view>
				</u-collapse-item>
			</u-collapse>
		</u-popup>

		<!-- 		<u-popup :show="pointListShow" :round="20" mode="bottom" :closeable="true" :overlay="false"
			:safeAreaInsetTop="true" @close="pointListShow = false">
			<view>资源列表</view>
			<u-list height="500px" v-if="pointList != false">		
				<u-list-item v-for="(item,index) in pointList" :key="index" style="margin-top:10px;">
					<u-cell :title="(index+1)+'、'+ item.Name" :label="`类型: ${item.Type || '空'}  地址:  ${item.Addr || '空'}`"
					@click="toShowPop(item)" isLink>
					</u-cell>
				</u-list-item>
			</u-list>
			<view style="height: 500px;" v-else>
				<u-empty mode="search"  height="500px">
				</u-empty>
			</view>		
		</u-popup> -->

		<u-popup :show="lineshow" :round="20" mode="bottom" :closeable="true" :overlay="false" :safeAreaInsetTop="true"
			@close="lineshow = false">
			<view>缆线列表</view>
			<u-list height="500px" v-if="clickLines != false">
				<u-list-item v-for="(item,index) in clickLines" :key="index" style="margin-top:10px;">
					<u-cell :title="(index+1)+'、'+ item.Name"
						:label="`类型: ${item.Ftype || '空'}  创建者:  ${item.Creator.Name || '空'} 芯数: ${item.Num || '空'} 缆线等级: ${item.Level || '空'}`"
						 :name="item.Id">
					</u-cell>
					<view style="display: flex; justify-content:space-around">
						<u-button :customStyle="{width: '100px'}" v-if='choosenLine.indexOf(item.Id)==-1' @click='toSingle(item.Id,item.ClickIdx)' type="success" size="mini">单独显示</u-button>
						<u-button :customStyle="{width: '100px'}" @click='toclickinsert(item.Id,item.ClickIdx)' type="primary" size="mini">点击插入</u-button>
						<u-button :customStyle="{width: '100px'}" @click="toinsertnode(item.Id,item.ClickIdx)" type="primary" size="mini">选择插入</u-button>
						<u-button :customStyle="{width: '100px'}" @click="toshowLine(item.Id)" type="primary" size="mini">详情</u-button>
						</view>
				</u-list-item>
			</u-list>
			<view style="height: 500px;" v-else>
				<u-empty mode="search" height="500px">
				</u-empty>
			</view>
		</u-popup>

		<u-popup :show="showpop" :round="20" mode="bottom" :closeable="true" :overlay="true" @close="close"
			:safeAreaInsetTop="true">
			<u-scroll-list>
				<u-list height="500px" v-for="(item,index) in items" :key="index">
					<u-list-item style="margin-top:10px;">
						<u-cell-group style=' width: 100%;'>
							<u-cell title="资源名称" :value="item.Name"></u-cell>
							<u-cell title="市、区/县" :value="item.City + item.District"></u-cell>
							<u-cell title="地址" :value="item.Addr"></u-cell>
							<!-- <u-cell title="编号" :value="item.No"></u-cell> -->
							<u-cell title="类型" :value="item.Type"></u-cell>
							<u-cell title="机房等级" :value="item.MachineRoomType" v-if="item.Type == '机房'"></u-cell>
							<u-cell title="坐标" :value="item.Lat + ',' + item.Lng"></u-cell>
							<u-cell title="采集人" :value="item.Creator.Name"></u-cell>
							<!-- 	<u-cell title="经度" :value="item.Lng"></u-cell>
							<u-cell title="纬度" :value="item.Lat"></u-cell> -->
							<u-cell title="备注" :value="item.Remark"></u-cell>
							<!-- <u-cell title="节点照片"></u-cell> -->
							<u-cell icon="list" title="设备列表" isLink @click="tolist(item.Id,item.Lat,item.Lng)"
								style="margin-top: 20px;"></u-cell>
							<u-cell icon="list-dot" title="缆线列表" isLink @click="toline(item.Id)"
								style="margin-top: 20px;"></u-cell>
							<u-cell icon="list-dot" title="照片列表" isLink @click="tophoto(item.Id)"
								style="margin-top: 20px;"></u-cell>
							<u-cell icon="car" title="导航至此" isLink @click="gomap(item.Lat,item.Lng)"
								style="margin-top: 20px;"></u-cell>
						</u-cell-group>
						<u-button type='primary' @click="tochange(item.Id)">编辑</u-button>
						<u-button
							v-if="(userinfo.Id == item.CreatorId && diffmonths(new Date(item.CreateTime).getTime(),nowDate) < 1 ) || userinfo.Roles.indexOf('管理员角色')>-1"
							type='error' @click="showconfirm=true">删除该点
						</u-button>
						<u-row>
							<u-col span="6">
								<u-button type='primary' @click="setselect(item.Id,item.Name)">设为测试点</u-button>
							</u-col>
							<u-col span="6">
								<u-button type='primary' @click="seterror(item.Id,item.Name)">设为故障点</u-button>
							</u-col>
						</u-row>
						<u-modal :content="'确定要删除吗？'" :show="showconfirm" showCancelButton closeOnClickOverlay
							@confirm="del(item.Id)" @cancel="showconfirm=false" @close="showconfirm=false"></u-modal>
					</u-list-item>
				</u-list>
			</u-scroll-list>
		</u-popup>

		<u-popup :show="showline" :round="20" mode="bottom" :closeable="true" :overlay="true" @close="showline = false"
			:safeAreaInsetTop="true">
			<u-list height="350px">
				<u-list-item v-for="(item,index) in Lineitems" :key="index" style="margin-top:10px;">
					<u-cell-group style=' width: 100%;'>
						<u-cell title="缆线名称" :value="item.Name"></u-cell>
						<u-cell title="类型" :value="item.Ftype"></u-cell>
						<u-cell title="地址" :value="item.Addr"></u-cell>
						<u-cell title="长度" :value="item.Length"></u-cell>
						<u-cell title="图上长度" :value="item.MapLong"></u-cell>
						<u-cell title="采集人" :value="CreatorName1"></u-cell>
						<u-cell title="芯数" :value="item.Num"></u-cell>
						<!-- <u-cell icon="pushpin" title="插入连接" isLink @click="toinsertnode(item.Id,item.ClickIdx)"
							style="margin-top: 20px;"></u-cell> -->
					</u-cell-group>
					<u-button
						v-if="(userinfo.Id == item.CreatorId && diffmonths(new Date(item.CreateTime).getTime(),nowDate) < 1 ) || userinfo.Roles.indexOf('管理员角色')>-1"
						type='primary' @click="tochangeLine(item.Id)">编辑</u-button>
					<u-button
						v-if="(userinfo.Id == item.CreatorId && diffmonths(new Date(item.CreateTime).getTime(),nowDate) < 1 ) || userinfo.Roles.indexOf('管理员角色')>-1"
						type='error' @click="showLineconfirm=true">删除缆线
					</u-button>
					<u-modal :content="'确定要删除吗？'" :show="showLineconfirm" showCancelButton closeOnClickOverlay
						@confirm="delLine(item.Id)" @cancel="showLineconfirm=false"
						@close="showLineconfirm=false"></u-modal>
				</u-list-item>
			</u-list>
		</u-popup>


		<u-modal :show="show" title="图例" :closeOnClickOverlay='true' @close="show =!show" @confirm="show =!show">
			<u-list height='300px'>
				<!-- <u-list-item v-for="(item, index) in columns" :key="index">
					<u-cell :title='item.name'>
						<u-avatar slot="icon" shape="square" size="35"
							:src="`https://project.gxrunxiang.com/cdn/icon${index + 11}.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item> -->
				<u-list-item>
					<u-cell title='井'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon11.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='接头盒'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon12.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='一级分纤箱'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon13.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='电杆'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon14.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='标桩'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon15.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='交接箱'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon16.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='分支分配器'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon17.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='集中分配器'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon18.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='光站'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon19.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='机房'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon20.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='二级分纤箱'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon21.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='地下管线拐点'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon22.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='墙挂支撑点'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon23.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='终端'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/icon24.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='管道'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/管道.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='直埋'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/直埋.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
				<u-list-item>
					<u-cell title='其他'>
						<u-avatar slot="icon" shape="square" size="35" :src="`https://project.gxrunxiang.com/cdn/其他.png`"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-list-item>
			</u-list>
		</u-modal>
		
		<u-modal title="数据" :show="modalshow" @confirm="connect" :closeOnClickOverlay="true"
			@close="modalshow = false,lineLength = '',laytype=''">
			<u-form labelWidth="auto" labelPosition="top">
				<u-form-item label="到该缆线起点的皮长(米)"><u-input v-model="lineLength" type="number" placeholder="请输入到该缆线起点的皮长(米)" /></u-form-item>
				<u-form-item label="至上一节点的敷设方式" @click="laytypeshow = true"><u-input disabled v-model="laytype"/></u-form-item>
			</u-form>
		</u-modal>
		
		<u-action-sheet :show="laytypeshow" :actions="typeColumns" title="请选择类型" @close="laytypeshow = false"
			@select="changelaytype">
		</u-action-sheet>
		
		<u-popup :show="showBroken" :round="20" mode="bottom" :closeable="true" :overlay="true" @close="showBroken = false"
			:safeAreaInsetTop="true">
			<u-cell-group style=' width: 100%;'>
				<u-cell icon="car" title="导航至此" isLink @click="gomap(endlola[1],endlola[0])"
					style="margin-top: 20px;"></u-cell>
			</u-cell-group>
		</u-popup>
		<u-toast ref="uToast" style="z-index: 999;"></u-toast>
	</view>
</template>

<script>
	import {
		getLinePathNodelist,
		getfilebyoutid,
		deleteLinePathNode,
		GetListByParent,
		getlinefiber,
		getlinefiberlist,
		delFiberNode,
		getClickFiberList,
		getSimpleNodeList,
		getClickMapList,
		getLineNodeList,
		deleteLinefiber,
		getClickNode,
		BrokenPoint,
		addFiberNode
	} from '@/common/api.js'
	import {
		baseUrl
	} from '@/common/config.js'
	import coordtransform from 'coordtransform'
	import color from '../../../uni_modules/uview-ui/libs/config/color'
	export default {
		data() {
			return {
				popdata: {},
				show: false,
				isimage: false,
				keyword: '',
				showpop: false,
				showline: false,
				showsheet: false,
				showconfirm: false,
				showloading: false,
				showselect: false,
				showBroken: false,
				pointListShow: false,
				showLineconfirm: false,
				needword: false,
				isIOS: false,
				isMc: false,
				laytypeshow: false,
				modalshow: false,
				seachlist: [],
				seachline: [],
				outdata: [],
				choosenLine: [],
				polylinedata: [], //线的中间数据
				columns: [],
				lineLength: '',
				laytype: '',
				typeColumns: [{name:'架空'},{name:'直埋'},{name:'管道'}],
				latitude: 22.56961, //地图的纬度
				longitude: 108.1307, //地图的经度
				scale: 17.02, //地图的缩放
				islocated: false,
				isselect: false,
				isloading: false,
				isadd: false,
				istonode: false,
				isMarkOver: true,
				isSingle: false,  //是否显示单独缆线
				singleFiberId: '', //单独缆线的Id
				clickInsertIdx: '', //点击插入时，插入点的序号
				insertNodeMarkerId: '', //单独插入时选择的点
				isInsert: false, //是否点击插入模式
				scaleHelp: false,
				markers: [], //地图中点的数据
				inmarkers: [],
				brokenmarkers: [],//断点的点数据
				polyline: [], //地图中线的数据
				inpolyline: [],
				brokenline:[],//断点的线数据
				userinfo: {}, //当前用户信息
				items: [], //点击点后获取的设施的数据
				Lineitems: [],
				startlola: [],
				CreatorName: "",
				CreatorName1: "",
				pointList: [], //点的列表
				mapContext: {},
				linefilter: {},
				linenode: "",
				TagX: '',
				TagY: '',
				tripleBox: {
					neLat: 0,
					neLng: 0,
					swLat: 180,
					swLng: 180,
				},
				clickLat: 0, //点击线时获取的纬度
				clickLng: 0, //点击线时获取的经度
				clickLines: [], //点击线时获取的线的数据
				iconurl: "",
				region: "",
				reqRoomOnly: false,
				reqNeedLevel: false,
				needLevel: false,
				seachshow: false,
				lineshow: false,
				loading: false,
				isBroken: false,
				scaleData: "",
				roomOnly: false,
				noFirst: false,
				pageIndex: 1, //当前页数
				pageSize: 20, //页数大小
				totalPage: "", //总页数
				total: 0, //数据总数
				status: 'loadmore', //加载状态
				listloading: false,
				loadingPageData: {
					// 自定义提示内容
					loadingText: '',
					// 自定义图片
					image: '',
					// 自定义加载动画模式
					loadingMode: '',
					// 自定义背景色
					bgColor: '#ffffff',
				},
				message: '',
				clickevent:null,
				deviceInfo:null,
				roomlimit: 16.47, //机房阈值
				textlimit: 19.75, //文字阈值
				levellimit: 13.33, //
				showingtext: false,
				lola: [], // 地图中心坐标
				nowDate: new Date().getTime(),
				noticeList: ['沿缆线方向，从后向前，点击资源点连续插入','flasdjfljlsf','dsjfsadljfljds'],
				selectId: '',
				selectName: '',
				errorId: '',
				errorName: '',
				fault:{
					Distance: 0
				},
				rules: {
					'Distance': {
						type: 'number',
						min: 0,
						required: true,
						message: '请填写故障距离',
						trigger: ['blur', 'change']
					},
				},
				
			}
		},
		methods: {
			//获取所有数据
			async getdata() {
				let para = {
					Parameters: [],
					orderBys: ["Id"],
				}
				if (this.scaleData <= this.roomlimit) {
					this.reqRoomOnly = true
					para.Parameters.push({
						FieldName: "Type",
						ConditionalType: "Equal",
						FieldValue: "机房",
					})
				} else { 
					para.Parameters = []
				}
				if(this.region){
					await getSimpleNodeList(this.region, para).then(res => {
						this.loading = false
						// console.log(res);
						this.outdata = res;
						// this.popdata = {}
						// res.data.forEach(e => {
						// 	this.popdata[e.Id] = e;
						// })
					})
					if(this.isSingle || this.isInsert){
						await getlinefiberlist('', this.singleFiberId, '').then(res => {
							this.polylinedata = res;
						})
					}else if (this.scaleData >= this.roomlimit) {
							await getlinefiberlist(this.region, '', '').then(res => {
								this.polylinedata = res;
						})
					}else if(this.scaleData > this.levellimit){
						await getlinefiberlist(this.region, '', '主干').then(res => {
								this.polylinedata = res;
						})
					}
				}
			},
			//进入微信导航页面
			gomap(Lat, Lng) {
				if (Lat, Lng) {
					let latitude = Lat
					let longitude = Lng
					var lola = coordtransform.wgs84togcj02(longitude, latitude)
					uni.openLocation({
						latitude: lola[1],
						longitude: lola[0],
						success: function() {
							console.log('success');
						}
					});
				}
			},
			toggleimg() {
				this.isimage = !this.isimage
			},
			async getlinelist() {
				let para = {}
				// this.linefilter = {
				// 	"ConditionalList": [{
				// 		"Key": 0,
				// 		"Value": {
				// 			"FieldName": "Name",
				// 			"FieldValue": this.keyword,
				// 			"ConditionalType": "Like"
				// 		}
				// 	}, {
				// 		"Key": 1,
				// 		"Value": {
				// 			"FieldName": "Type",
				// 			"FieldValue": this.keyword,
				// 			"ConditionalType": "Like"
				// 		}
				// 	}]
				// }
				// para.jsonPara=JSON.stringify( [this.linefilter])
				para.OrderBys = ['CreateTime desc']
				para.pageSize = this.pageSize
				para.pageIndex = this.pageIndex
				para.Parameters = []
				this.mapContext = uni.createMapContext("maps", this);
				this.mapContext.getCenterLocation({
					type: 'gcj02',
					success: (res) => {
						var lola = coordtransform.gcj02towgs84(res.longitude, res.latitude)
						getLineNodeList(this.keyword, lola[0], lola[1], para).then(res => {
							this.message = ""
							if (res.code < 0) {
								this.message = res.message
							}
							this.seachlist.push(...res.data.node)
							this.seachline.push(...res.data.line)
							this.total = res.count
							this.totalPage = Math.ceil(this.total / this.pageSize)
						})
						if (this.seachlist.length < this.pageSize) {
							this.loading = false; //如果数据列表小于当前页数，就让加载标签消失
							this.status = 'nomore';
						} else {
							this.status = 'loadmore';
						}
					},
				})
			},
			//查找方法
			searchlist() {
				if (this.keyword.length != 0)
					this.seachshow = true
				else {
					this.seachshow = false
					return
				}
				this.seachlist = [] //初始化
				this.seachline = []
				this.pageIndex = 1 //初始化当前页数为1
				this.listloading = true
				this.getlinelist()
			},
			//选择并跳转到地点
			tonode(item) {
				this.seachshow = false
				this.showloading = true
				this.istonode = true
				if (item.Coordinate) {
					let arr = JSON.parse(item.Coordinate)
					var latitude = arr[0][1]
					var longitude = arr[0][0]
				} else {
					var latitude = item.Lat
					var longitude = item.Lng
				}
				var lola = coordtransform.wgs84togcj02(longitude, latitude)
				this.longitude = lola[0]
				this.latitude = lola[1]
				if (this.scaleHelp == false) {
					this.scale = 21.98
				} else {
					this.scale = 21.97
				}
				this.scaleHelp = !this.scaleHelp
				if (item.Coordinate) {
					let para = {
						Parameters: [],
						OrderBys: ['CreateTime desc']
					}
					para.Parameters.push({
						FieldName: "Id",
						ConditionalType: "Equal",
						FieldValue: item.Id
					})
					this.toSingle(item.Id)
					getlinefiber('', para).then(res => {
						this.Lineitems[0] = res.data[0]
						if (this.Lineitems[0].Creator) {
							this.CreatorName1 = this.Lineitems[0].Creator.Name
						} else {
							this.CreatorName1 = ""
						}
						this.showloading = false
						this.showline = true
					})
				} else {
					let para = {
						Parameters: [],
					}
					para.Parameters.push({
						FieldName: "Id",
						ConditionalType: "Equal",
						FieldValue: item.Id
					})
					getLinePathNodelist("", para).then(res => {
						this.items[0] = res.data[0]
						if (this.items[0].Creator) {
							this.CreatorName = this.items[0].Creator.Name
						} else {
							this.CreatorName = ""
						}
						this.showloading = false
						this.showpop = true
					})
				}
				// console.log(this.scale);
			},
			showNLLine(Id) {
				let para = {
					Parameters: [],
				}
				para.Parameters.push({
					FieldName: "Id",
					ConditionalType: "Equal",
					FieldValue: Id
				})
				getlinefiber('', para).then(res => {
					this.Lineitems[0] = res.data[0]
					if (this.Lineitems[0].Creator) {
						this.CreatorName1 = this.Lineitems[0].Creator.Name
					} else {
						this.CreatorName1 = ""
					}
					this.seachshow = false
					this.showline = true
				})
			},
			toshowLine(e) {
				this.showpop = false
				let para = {
					Parameters: [],
					OrderBys: ['CreateTime desc']
				}
				para.Parameters.push({
					FieldName: "Id",
					ConditionalType: "Equal",
					FieldValue: e
				})
				getlinefiber('', para).then(res => {
					this.Lineitems[0] = res.data[0]
					if (this.Lineitems[0].Creator) {
						this.CreatorName1 = this.Lineitems[0].Creator.Name
					} else {
						this.CreatorName1 = ""
					}
					this.lineshow = false
					this.showline = true
				})
			},
			toSingle(fiberId,clickIdx){ //单独显示
				this.isSingle = true
				this.singleFiberId = fiberId
				// this.singleClickIdx = clickIdx
				this.lineshow = false
				this.setMarkers()
			},
			exittoSingle(){
				this.isSingle = false
				this.singleFiberId = ''
				// this.singleClickIdx = ''
				this.setMarkers()
			},
			toclickinsert(fiberId,clickIdx){
				this.singleFiberId = fiberId
				this.clickInsertIdx = clickIdx
				this.isInsert = true
				this.lineshow = false
				this.setMarkers()
			},
			exitclickinsert(){
				this.singleFiberId = ''
				this.clickInsertIdx = ''
				this.isInsert = false
				this.setMarkers()
			},
			onfocus() {
				if (this.keyword != "") {
					this.seachshow = true
				}
			},
			//设置地图上的点
			async setMarkers() {
				this.loading = true
				await this.getdata()
				this.reqRoomOnly = this.scaleData <= this.roomlimit
				this.reqNeedLevel = this.scaleData < this.levellimit
				this.outdatatomarkers()
				if (this.scaleData >= this.roomlimit || this.isSingle || this.isInsert || this.scaleData > this.levellimit) {
					this.inpolyline=[]
					this.polyline=[]
					this.polylinedata.forEach(e => {
						let linearr = []
						let texts = []
						let colorslist = []
						for (let i = 0; i <= e.LngLat.length - 1; i++) {
							var lola = coordtransform.wgs84togcj02(e.LngLat[i][0], e.LngLat[i][1])
							linearr.push({
								latitude: lola[1],
								longitude: lola[0]
							})
							texts.push({
								name: e.TextList[i],
								startIndex: i,
								endIndex: i + 1
							})
							colorslist.push(e.ColorList[i])
						}
						// console.log(e.Level,e.Name)
						this.inpolyline.push({
							points: linearr,
							// id: e.Id,
							level: "abovebuildings",
							// color: '#e27728',
							colorList: colorslist,
							segmentTexts: texts,
							textStyle: {
								textColor: "#000000",
								strokeColor: "#ffffff",
								fontSize: 14
							},
							width: e.Level == '主干' ? 6 : 3,
							arrowLine: true
						})
					})
					if(this.isBroken == true){
						this.inpolyline = this.inpolyline.concat(this.brokenline)
					}
					this.polyline = this.inpolyline
				} else {
					this.polyline = []
				}
			},
			outdatatomarkers() {
				var needtext = (this.scaleData >= this.textlimit && (this.deviceInfo.platform!="windows" && this.deviceInfo.platform!="devtools"))
				this.inmarkers = [];
				this.markers=[];
				this.outdata.forEach(e => {
					let latitude = e.Lat
					let longitude = e.Lng
					var lola = coordtransform.wgs84togcj02(longitude, latitude)
					let Name = e.Name.replace(/[^\x00-\xff]/g, "$&\x01").replace(/.{10}\x01?/g, "$&\n")
						.replace(/\x01/g, "")
					this.inmarkers.push({
						longitude: lola[0],
						latitude: lola[1],
						id: e.MarkId,
						iconPath: this.geticon(e.Type),
						width: 18,
						height: 18,
						anchor: {
							x: 0.5,
							y: 0.8
						},
						zIndex: 999,
						label: !needtext ? null : {
							content: Name,
							textAlign: 'right',
							anchorX: this.isIOS ? 0 : 10,
							anchorY: -15
						},
						tId: e.Id
					})
				})
				if(this.isBroken == true){
					this.inmarkers = this.inmarkers.concat(this.brokenmarkers)
				}
				this.markers = this.inmarkers
				this.showingtext = needtext
			},
			//点击地图上点的事件
			clickMarker(event) {
				this.clickevent="point"
				if(this.isInsert){
					this.modalshow = true
					this.insertNodeMarkerId = event.markerId
				}else{
					if(event.markerId == 1290001){
						this.showBroken = true
					}else{				
						this.showloading = true
						// if(this.isMc == true)
						// return;
						let para = {
							Parameters: [],
						}
						// para.Parameters.push({
						// 	FieldName: "MarkId",
						// 	ConditionalType: "Equal",
						// 	FieldValue: event.markerId
						// })
						getClickNode(event.markerId, 0, para).then(res => {
							this.clickevent=null
							this.items = res
							// if(this.items[0].Creator){
							// 	this.CreatorName = this.items[0].Creator.Name
							// }
							// else{
							// 	this.CreatorName = ""
							// }
							this.showloading = false
							this.showpop = true
						})
						// getLinePathNodelist("",para).then(res => {
						// 	this.items[0] = res.data[0]
						// 	if(this.items[0].Creator){
						// 		this.CreatorName = this.items[0].Creator.Name
						// 	}
						// 	else{
						// 		this.CreatorName = ""
						// 	}
						// 	this.showpop = true
						// 	// var Lng = res.data[0].Lng
						// 	// var Lat = res.data[0].Lat
						// 	// getClickMapList(this.region,res.data[0].Lat,res.data[0].Lng,para).then(res => {
						// 	// 	if(res.points.length > 1){
						// 	// 		this.pointList = res.points
						// 	// 		this.pointListShow = true
						// 	// 	}else if(res.points.length == 1){
						// 	// 		this.items[0] = res.points[0]
						// 	// 		this.showpop = true
						// 	// 	}else{
						// 	// 		this.clickLines = res.lines
						// 	// 		this.lineshow = true
						// 	// 	}
						// 	// })
						// })
						
						// this.items[0] = this.popdata[event.markerId]
						// this.outdata.find(item => item.Id === event.markerId)
						// this.showpop = true
						}
				}
			},
			//删除
			del(id) {
				// let p = [this.item.Id]
				let p = [id]
				deleteLinePathNode(p).then(res => {
					this.markers = []
					this.setMarkers()
					this.showconfirm = false
					this.showpop = false
				})
			},
			delLine(Id) {
				let ids = [Id]
				deleteLinefiber(ids).then((res) => {
					if (res == true)
						this.markers = []
					this.setMarkers()
					this.showLineconfirm = false
					this.showline = false
				})
			},
			//关闭详情
			close() {
				this.showpop = false;
			},
			//进入页面时获取当前位置
			outlocation() {
				// uni.getLocation({
				// 	type: 'wgs84',
				// 	geocode: true, //设置该参数为true可直接获取经纬度及城市信息
				// 	success: (res) => {
				// 		// console.log("定位结果" + res.longitude + "，" + res.latitude)
				// 		// that.addrDel = res;		
				// 		var lola = coordtransform.wgs84togcj02(res.longitude, res.latitude)
				// 		this.longitude = lola[0]
				// 		this.latitude = lola[1]
				// 		this.islocated = true
				// 	},
				// 	fail: () => {
				// 		// this.outcenter = [111.11111, 11.111111]
				// 		// console.log("定位结果失败")
				// 		// console.log(this)
				// 		uni.showToast({
				// 			title: '获取地址失败，将导致部分功能不可用',
				// 			icon: 'none'
				// 		});
				// 	}
				// });
				wx.getLocation({
					type: 'gcj02',
					isHighAccuracy: true,
					success: (res) => {
						// console.log("定位结果" + res.longitude + "，" + res.latitude)
						// that.addrDel = res;		
						// var lola = coordtransform.wgs84togcj02(res.longitude, res.latitude)
						this.longitude = res.longitude
						this.latitude = res.latitude
						this.islocated = true
					},
					fail: () => {
						// this.outcenter = [111.11111, 11.111111]
						// console.log("定位结果失败")
						// console.log(this)
						uni.showToast({
							title: '获取地址失败，将导致部分功能不可用',
							icon: 'none'
						});
					}
				})
			},
			geticon(Type) {
				switch (Type) {
					case "井":
						return "https://project.gxrunxiang.com/cdn/icon11.png"
						break;
					case "接头盒":
						return "https://project.gxrunxiang.com/cdn/icon12.png"
						break;
					case "一级分纤箱":
						return "https://project.gxrunxiang.com/cdn/icon13.png"
						break;
					case "电杆":
						return "https://project.gxrunxiang.com/cdn/icon14.png"
						break;
					case "标桩":
						return "https://project.gxrunxiang.com/cdn/icon15.png"
						break;
					case "交接箱":
						return "https://project.gxrunxiang.com/cdn/icon16.png"
						break;
					case "分支分配器":
						return "https://project.gxrunxiang.com/cdn/icon17.png"
						break;
					case "集中分配器":
						return "https://project.gxrunxiang.com/cdn/icon18.png"
						break;
					case "光站":
						return "https://project.gxrunxiang.com/cdn/icon19.png"
						break;
					case "机房":
						return "https://project.gxrunxiang.com/cdn/icon20.png"
						break;
					case "二级分纤箱":
						return "https://project.gxrunxiang.com/cdn/icon21.png"
						break;
					case "野外型小C":
						return "https://project.gxrunxiang.com/cdn/icon22.png"
						break;
					case "地下管线拐点":
						return "https://project.gxrunxiang.com/cdn/icon23.png"
						break;
					case "挂墙支持点":
						return "https://project.gxrunxiang.com/cdn/icon24.png"
						break;
				}
			},
			//获取当前位置并且添加点
			setLocation() {
				this.isloading = true
				wx.getLocation({
					type: 'gcj02',
					isHighAccuracy: true,
					success: (res) => {
						// var lola = coordtransform.wgs84togcj02(res.longitude, res.latitude)
						this.longitude = res.longitude
						this.latitude = res.latitude
						this.markers.push({
							longitude: res.longitude,
							latitude: res.latitude,
							id: 'nowLocation',
							iconPath: 'https://project.gxrunxiang.com/cdn/iconz.png',
							width: 21,
							height: 21
						})
						this.islocated = true
						this.scale = 16.5
						this.isloading = false
					},
					fail: () => {
						uni.showToast({
							title: '获取地址失败，将导致部分功能不可用',
							icon: 'none'
						});
					},

				});
			},

			//显示选定按钮和地图中心的图标
			toggleSelect() {
				this.isselect = !this.isselect
			},
			inselect() {
				//点击选定时获取当前地图中心的坐标,并进入页面
				this.mapContext = uni.createMapContext("maps", this);
				this.mapContext.getCenterLocation({
					type: 'gcj02',
					success: (res) => {
						var lola = coordtransform.gcj02towgs84(res.longitude, res.latitude)
						let lat = lola[1]
						let lng = lola[0]
						uni.navigateTo({
							url: `linepathnodePonit?lat=${lat}&lng=${lng}`
						})
					},
				})
			},
			toRegionChange(e) {
				if (e.type == 'end') {
					this.mapContext = uni.createMapContext("maps", this);
					this.scaleData = e.detail.scale
					this.mapContext.getRegion({
						success: res => {
							// if (this.loading == true)
							// 	return;
							var screenBox = {
								northeast: {
									latitude: res.northeast.latitude,
									longitude: res.northeast.longitude
								},
								southwest: {
									latitude: res.southwest.latitude,
									longitude: res.southwest.longitude
								}
							}
							// if(this.scaleData <= 16.47){
							// 	this.roomOnly = true
							// }else if(this.scaleData > 16.47){
							// 	this.roomOnly = false
							// }
							this.roomOnly = this.scaleData <= this.roomlimit
							this.needLevel = this.scaleData < this.levellimit
							this.needword = this.scaleData > this.textlimit
							var newBox = this.isInbox(screenBox, this.tripleBox)
							// if(newBox || (this.roomOnly == false && this.reqRoomOnly == true)){
							//当前框超过三倍框，或请求过机房但又缩小时，需要重新请求
							// if(newBox){
							// 	this.tripleBox = newBox
							// }else{
							// 	this.tripleBox.neLat = screenBox.northeast.latitude  + (screenBox.northeast.latitude - screenBox.southwest.latitude)
							// 	this.tripleBox.neLng = screenBox.northeast.longitude + ( screenBox.northeast.longitude - screenBox.southwest.longitude)
							// 	this.tripleBox.swLat = screenBox.southwest.latitude  - (screenBox.northeast.latitude - screenBox.southwest.latitude)
							// 	this.tripleBox.swLng = screenBox.southwest.longitude - ( screenBox.northeast.longitude - screenBox.southwest.longitude)
							// 	this.reqRoomOnly = false
							// }
							// var lola1 = coordtransform.gcj02towgs84(this.tripleBox.swLng, this.tripleBox.swLat)
							// var lola2 = coordtransform.gcj02towgs84(this.tripleBox.neLng, this.tripleBox.neLat)
							// this.region = lola1[0].toString() + ',' +
							// 	lola1[1].toString() + ',' +
							// 	lola2[0].toString() + ',' +
							// 	lola2[1].toString();
							if (newBox || this.roomOnly != this.reqRoomOnly || this.needLevel != this.reqNeedLevel) {
								this.setRegion(screenBox)
								this.inmarkers = [];
								this.inpolyline = [];
								this.setMarkers()
							} else if (this.needword != this.showingtext) {
								this.outdatatomarkers()
							}
						},
						// } else {
						// 	//当前框不超过三倍框，不需要请求
						// 	if (this.roomOnly && this.reqRoomOnly == false) {
						// 		var lola1 = coordtransform.gcj02towgs84(this.tripleBox.swLng, this
						// 			.tripleBox.swLat)
						// 		var lola2 = coordtransform.gcj02towgs84(this.tripleBox.neLng, this
						// 			.tripleBox.neLat)
						// 		this.region = lola1[0].toString() + ',' +
						// 			lola1[1].toString() + ',' +
						// 			lola2[0].toString() + ',' +
						// 			lola2[1].toString();
						// 		this.inmarkers = [];
						// 		this.inpolyline = [];
						// 		this.setMarkers()
						// 	} else if (this.scaleData > 21 && !this.needword) {
						// 		this.needword = true
						// 		this.inmarkers = []
						// 		this.outdata.forEach(e => {
						// 			let latitude = e.Lat
						// 			let longitude = e.Lng
						// 			var lola = coordtransform.wgs84togcj02(longitude, latitude)

						// 			let Name = e.Name.replace(/[^\x00-\xff]/g, "$&\x01").replace(
						// 				/.{10}\x01?/g, "$&\n").replace(/\x01/g, "")
						// 			this.inmarkers.push({
						// 				longitude: lola[0],
						// 				latitude: lola[1],
						// 				id: e.MarkId,
						// 				iconPath: this.geticon(e.Type),
						// 				width: 18,
						// 				height: 18,
						// 				label: {
						// 					content: Name,
						// 					textAlign: 'right',
						// 					anchorX: this.isIOS ? 0 : 10,
						// 					anchorY: -15
						// 				},
						// 				anchor: {
						// 					x: 0.5,
						// 					y: 0.8
						// 				},
						// 				zIndex: 999
						// 			})
						// 			this.markers = this.inmarkers
						// 		})
						// 	} else if (this.scaleData < 21 && this.needword) {
						// 		this.needword = false
						// 		this.inmarkers = []
						// 		this.outdata.forEach(e => {
						// 			let latitude = e.Lat
						// 			let longitude = e.Lng
						// 			var lola = coordtransform.wgs84togcj02(longitude, latitude)

						// 			let Name = e.Name.replace(/[^\x00-\xff]/g, "$&\x01").replace(
						// 				/.{10}\x01?/g, "$&\n").replace(/\x01/g, "")
						// 			this.inmarkers.push({
						// 				longitude: lola[0],
						// 				latitude: lola[1],
						// 				id: e.MarkId,
						// 				iconPath: this.geticon(e.Type),
						// 				width: 18,
						// 				height: 18,
						// 				anchor: {
						// 					x: 0.5,
						// 					y: 0.8
						// 				},
						// 				zIndex: 999
						// 			})
						// 		})
						// 		this.markers = this.inmarkers
						// 	}
						// }
						// if (this.polyline.length == 0 && this.scaleData >= 16.48) {
						// 	this.inpolyline = []
						// 	this.polylinedata.forEach(e => {
						// 		let linearr = []
						// 		let texts = []
						// 		let colorslist = []
						// 		for (let i = 0; i <= e.LngLat.length - 1; i++) {
						// 			var lola = coordtransform.wgs84togcj02(e.LngLat[i][0], e
						// 				.LngLat[i][1])
						// 			linearr.push({
						// 				latitude: lola[1],
						// 				longitude: lola[0]
						// 			})
						// 			texts.push({
						// 				name: e.TextList[i],
						// 				startIndex: i,
						// 				endIndex: i + 1
						// 			})
						// 			colorslist.push(e.ColorList[i])
						// 		}
						// 		this.inpolyline.push({
						// 			points: linearr,
						// 			// id: e.Id,
						// 			level: "abovebuildings",
						// 			// color: '#e27728',
						// 			colorList: colorslist,
						// 			segmentTexts: texts,
						// 			textStyle: {
						// 				textColor: "#000000",
						// 				strokeColor: "#ffffff",
						// 				fontSize: 14
						// 			},
						// 			width: 3
						// 		})
						// 	})
						// 	this.polyline = this.inpolyline
						// } else if (this.scaleData < 16.48) {
						// 	this.polyline = []
						// }

						// if(this.scaleData > 15.5 && this.needword == true){
						// 	this.needword = false
						// 	this.neLat = res.northeast.latitude
						// 	this.neLng = res.northeast.longitude
						// 	this.swLat = res.southwest.latitude
						// 	this.swLng = res.southwest.longitude
						// 	var lola1 = coordtransform.gcj02towgs84(this.swLng, this.swLat)
						// 	var lola2 = coordtransform.gcj02towgs84(this.neLng, this.neLat)
						// 	this.region = lola1[0].toString() + ',' +
						// 		lola1[1].toString() + ',' +
						// 		lola2[0].toString() + ',' +
						// 		lola2[1].toString();
						// 	// console.log(this.region);
						// 	this.inmarkers = [];
						// 	this.inpolyline = [];
						// 	this.setMarkers()
						// }
						// if(this.scaleData > 13.4 && this.zz){
						// 	this.needref = false
						// 	var lola1 = coordtransform.gcj02towgs84(this.swLng, this.swLat)
						// 	var lola2 = coordtransform.gcj02towgs84(this.neLng, this.neLat)
						// 	this.region = lola1[0].toString() + ',' +
						// 		lola1[1].toString() + ',' +
						// 		lola2[0].toString() + ',' +
						// 		lola2[1].toString();
						// 	// console.log(this.region);
						// 	this.inmarkers = [];
						// 	this.inpolyline = [];
						// 	this.setMarkers()
						// }else if (this.istonode == true){
						// 	this.istonode = false
						// 	this.neLat = res.northeast.latitude  + (res.northeast.latitude - res.southwest.latitude)
						// 	this.neLng = res.northeast.longitude + ( res.northeast.longitude - res.southwest.longitude)
						// 	this.swLat = res.southwest.latitude  - (res.northeast.latitude - res.southwest.latitude)
						// 	this.swLng = res.southwest.longitude - ( res.northeast.longitude - res.southwest.longitude)
						// 	var lola1 = coordtransform.gcj02towgs84(this.swLng, this.swLat)
						// 	var lola2 = coordtransform.gcj02towgs84(this.neLng, this.neLat)
						// 	this.region = lola1[0].toString() + ',' +
						// 		lola1[1].toString() + ',' +
						// 		lola2[0].toString() + ',' +
						// 		lola2[1].toString();
						// 	// console.log(this.region);
						// 	this.inmarkers = [];
						// 	this.inpolyline = [];
						// 	this.setMarkers()
						// }
						// else if (this.neLat >= res.northeast.latitude && this.neLng >= res.northeast
						// 	.longitude &&
						// 	this.swLat <= res.southwest.latitude && this.swLng <= res.southwest.longitude
						// ) {
						// 	console.log('视图放大了');
						// } else {
						// 	if (this.neLat < res.northeast.latitude) {
						// 		this.neLat = res.northeast.latitude  + (res.northeast.latitude - res.southwest.latitude)
						// 	}
						// 	if (this.neLng < res.northeast.longitude) {
						// 		this.neLng = res.northeast.longitude + ( res.northeast.longitude - res.southwest.longitude)
						// 	}
						// 	if (this.swLat > res.southwest.latitude) {
						// 		this.swLat = res.southwest.latitude  - (res.northeast.latitude - res.southwest.latitude)
						// 	}
						// 	if (this.swLng > res.southwest.longitude) {
						// 		this.swLng = res.southwest.longitude - ( res.northeast.longitude - res.southwest.longitude)
						// 	}
						// 	var lola1 = coordtransform.gcj02towgs84(this.swLng, this.swLat)
						// 	var lola2 = coordtransform.gcj02towgs84(this.neLng, this.neLat)
						// 	this.region = lola1[0].toString() + ',' +
						// 		lola1[1].toString() + ',' +
						// 		lola2[0].toString() + ',' +
						// 		lola2[1].toString();
						// 	// console.log(this.region);
						// 	this.inmarkers = [];
						// 	this.inpolyline = [];
						// 	this.setMarkers()
						// }
						// },
						fail: (data, code) => {
							console.log('fail' + JSON.stringify(data));
						}
					})
				}
			},
			tonodedetail(e) {
				uni.navigateTo({
					url: `linefiberdetail?Id=${e.Name}`
				})
			},
			tolinedetail(e) {
				uni.navigateTo({
					url: `linefiberdetail?Id=${e.Name}`
				})
			},
			tolist(Id, Lat, Lng) {
				uni.navigateTo({
					url: `lineequlist?NodeId=${Id}&Lat=${Lat}&Lng=${Lng}`
				})
			},
			tochange(Id) {
				this.showpop = false
				uni.navigateTo({
					url: `linepathnodePonit?Id=${Id}`
				})
			},
			tochangeLine(Id) {
				this.showline = false
				uni.navigateTo({
					url: `addlinefiber?Id=${Id}`
				})
			},
			toline(Id) {
				uni.navigateTo({
					url: `linefibernode?NodeId=${Id}&Region=${this.region}`
				})
			},
			tophoto(Id) {
				uni.navigateTo({
					url: `linenodePhoto?Id=${Id}`
				})
			},
			clickmap(e){
				if(this.deviceInfo.platform!="windows" && this.deviceInfo.platform!="devtools")
				return;
				this.clickLine(e)
			},
			clickLine(e) {
				if(this.clickevent!=null)
				 return;
				this.showloading = true
				var lola = coordtransform.gcj02towgs84(e.detail.longitude, e.detail.latitude)
				this.clickLng = lola[0]
				this.clickLat = lola[1]
				if(this.isSingle || this.isInsert){
					getClickFiberList(this.region, lola[1], lola[0], this.singleFiberId).then(res => {
						this.clickLines = res
						this.showloading = false
						this.lineshow = true
					})
				}else{
					getClickFiberList(this.region, lola[1], lola[0], '').then(res => {
						this.clickLines = res
						this.showloading = false
						this.lineshow = true
					})
				}
				
				this.clickevent=null
			},
			isInbox(screenBox, tripleBox) {

				//screenBox 当前屏幕框 Box  tripleBox 保存的三倍框 return false代表不需要改变 return newBox代表新的三倍框
				if (tripleBox.neLat < screenBox.northeast.latitude || tripleBox.neLng < screenBox.northeast.longitude ||
					tripleBox.swLat > screenBox.southwest.latitude || tripleBox.swLng > screenBox.southwest.longitude) {
						this.setRegion(screenBox)
					return true
					
				} else {
					return false
				}
			},
			setRegion(screenBox) {
				var newBox = {}
				newBox.neLat = screenBox.northeast.latitude + (screenBox.northeast.latitude - screenBox.southwest
					.latitude)
				newBox.neLng = screenBox.northeast.longitude + (screenBox.northeast.longitude - screenBox.southwest
					.longitude)
				newBox.swLat = screenBox.southwest.latitude - (screenBox.northeast.latitude - screenBox.southwest
					.latitude)
				newBox.swLng = screenBox.southwest.longitude - (screenBox.northeast.longitude - screenBox.southwest
					.longitude)
				this.tripleBox = newBox;	
				var lola1 = coordtransform.gcj02towgs84(this.tripleBox.swLng, this.tripleBox.swLat)
				var lola2 = coordtransform.gcj02towgs84(this.tripleBox.neLng, this.tripleBox.neLat)
				this.region = lola1[0].toString() + ',' +
					lola1[1].toString() + ',' +
					lola2[0].toString() + ',' +
					lola2[1].toString();
			},
			// clickLine(e){
			// 	let para = {
			// 		Parameters: [],
			// 	}
			// 	var lola = coordtransform.gcj02towgs84(e.detail.longitude, e.detail.latitude)
			// 	this.clickLng = lola[0]
			// 	this.clickLat = lola[1]
			// 	getClickMapList(this.region,lola[1],lola[0],para).then(res => {
			// 		if(res.points.length > 1){
			// 			this.pointList = res.points
			// 			this.pointListShow = true
			// 		}else if(res.points.length == 1){
			// 			this.items[0] = res.points[0]
			// 			this.showpop = true
			// 		}else if(res.lines.length > 0){
			// 			this.clickLines = res.lines
			// 			this.lineshow = true
			// 		}
			// 	})
			// },
			toinsertnode(Id, ClickIdx) {
				let regions = ""
				this.mapContext = uni.createMapContext("maps", this);
				this.mapContext.getRegion({
					success: res => {
						let lola1 = coordtransform.gcj02towgs84(res.southwest.longitude, res.southwest
							.latitude)
						let lola2 = coordtransform.gcj02towgs84(res.northeast.longitude, res.northeast
							.latitude)
						regions = lola1[0].toString() + ',' +
							lola1[1].toString() + ',' +
							lola2[0].toString() + ',' +
							lola2[1].toString();
						this.lineshow = false
						uni.navigateTo({
							url: `insertnode?Id=${Id}&region=${regions}&index=${ClickIdx}`
						})
					},
				})
			},
			diffmonths(time1, time2) {
				var diffSeconds = Math.abs(time2 - time1) / 1000;
				var diffMonths = Math.floor(diffSeconds / (24 * 60 * 60 * 15));
				return diffMonths
			},
			setselect(Id,Name){
				this.selectId = Id;
				this.selectName = Name;
				this.showpop = false;
				console.log(this.showpop)
				if(this.selectName!='' && this.errorName!=''){
					this.showselect = true;
				}
			},
			seterror(Id,Name){
				this.errorId = Id;
				this.errorName = Name;
				this.showpop = false;
				if(this.selectName!='' && this.errorName!=''){
					this.showselect = true
				}
			},
			//清除断点和线，并重新获取其他点
			clearChoose(){
				this.selectId = '';
				this.selectName = '';
				this.errorId = '';
				this.errorName = '';
				this.isBroken = false;
				this.inmarkers = [];
				this.inpolyline = [];
				this.setMarkers()
				this.brokenmarkers = [];
				this.brokenline = [];
				this.endlola = [];
				this.startlola = [];
			},
			showSelect(){
				this.showselect = true
			},
			timeoutSelect(){
				if(this.endlola != []){
					this.showloading = false;
					this.isBroken = false;
					uni.$u.toast('查询超时')
				}
			},
			toSelect(){
				this.isBroken = true;
				this.showloading  = true;
				this.showselect = false;
				//添加计时器，120S超时后自动去除加载框
				let timerId = setTimeout(()=>{
					this.timeoutSelect()
				},120000);
				this.$refs.uForm.validate().then(resq => {
					//获取断点与线
					BrokenPoint(this.selectId,this.errorId,this.fault.Distance).then(res => {
					if(res.length != 0){
						let datas = res;
						this.brokenmarkers = [];
						this.brokenline = [];
						for(var i = 0; i < datas.length; i++){
							var nums = datas[i].length - 1
							var linearr = []
							datas[i].forEach(e => {
								// for(var i = 0;i < e.length - 1;i++){
									var lola = coordtransform.wgs84togcj02(e[0], e[1]);
									linearr.push({
										latitude: lola[1],
										longitude: lola[0]
									})
								// }			
							})
							this.brokenline.push({
								points: linearr,
								level: "abovebuildings",
								color: '#e27728',
								width: 6,
								dottedLine: true
							})
							this.startlola = coordtransform.wgs84togcj02(datas[i][0][0], datas[i][0][1]);
							this.endlola = coordtransform.wgs84togcj02(datas[i][nums][0], datas[i][nums][1]);
							if(i == 0){
								this.brokenmarkers.push({
									longitude: this.startlola[0],
									latitude: this.startlola[1],
									id: 224,
									iconPath: 'https://project.gxrunxiang.com/cdn/csd.png',
									width: 18,
									height: 18,
									anchor: {
										x: 0.5,
										y: 0.8
									},
									zIndex: 999,
									label: {
										content: '测试点',
										textAlign: 'right',
										anchorX: this.isIOS ? 0 : 10,
										anchorY: -15
									},
								})
							}
							
							this.brokenmarkers.push({
								longitude: this.endlola[0],
								latitude: this.endlola[1],
								id: 1290001,
								iconPath: 'https://project.gxrunxiang.com/cdn/mdd.png',
								width: 18,
								height: 18,
								anchor: {
									x: 0.5,
									y: 0.8
								},
								zIndex: 999,
								label: {
									content: '断点',
									textAlign: 'right',
									anchorX: this.isIOS ? 0 : 10,
									anchorY: -15
								},
							})	
						}
						//在当前点和线列表中加入断点与线
						this.inmarkers = this.inmarkers.concat(this.brokenmarkers)
						this.markers = this.inmarkers;
						this.inpolyline = this.inpolyline.concat(this.brokenline)
						this.polyline = this.inpolyline;
						//定位到断点
						this.longitude = this.endlola[0]
						this.latitude = this.endlola[1]
						if (this.scaleHelp == false) {
							this.scale = 21.98
						} else {
							this.scale = 21.97
						}
						this.scaleHelp = !this.scaleHelp;
						this.showloading  = false;
						clearTimeout(timerId);
					}else{
						uni.$u.toast('两点无缆线连接!')
						this.isBroken = false;
						this.showloading  = false;
						clearTimeout(timerId);
					}
					})
				}).catch(errors => {
					uni.$u.toast('请填写必填参数！')
				})
			},
			inputVal(val){
				let temp = val.replace(/[^0-9.]+/g, '')
				this.$nextTick(()=>{
					this.fault.Distance = temp
				})
			},
			connect(){
				let para = {
					fiberId: this.singleFiberId,
					nodeId: this.inmarkers.find(e => e.id == this.insertNodeMarkerId).tId,
					length: this.lineLength,
					layType: this.laytype
				}
				addFiberNode(this.clickInsertIdx,para).then(res => {
					this.modalshow = false
					if (res.code == 0) {
						this.$refs.uToast.show({
							message: res.message,
							type: 'success',
							position: 'top',
							duration: 1000
						})
						this.clickInsertIdx = this.clickInsertIdx + 1
						this.lineLength = ''
						this.laytype = ''
						this.setMarkers()
					} else {
						this.$refs.uToast.show({
							message: res.message,
							type: 'error',
							position: 'top',
							duration: 1000
						})
					}
				})
			},
			changelaytype(e) {
				this.laytype = e.name
			},
			// toShowPop(item){
			// 	this.items[0] = item
			// 	this.pointListShow = false
			// 	this.showpop = true
			// }
		},

		onLoad() {
			GetListByParent("线路节点类型", this.columns)
			if (uni.getSystemInfoSync().platform == 'ios') {
				this.isIOS = true
			} else {
				this.isIOS = false
			}
			if (uni.getSystemInfoSync().platform == 'windows') {
				this.isMc = true
			} else {
				this.isMc = false
			}
		},
		onReady() {
			//onReady 为uni-app支持的生命周期之一
			this.$refs.uForm.setRules(this.rules)
		},
		onShow() {
			this.userinfo = JSON.parse(uni.getStorageSync("$userinfo"))
			this.choosenLine = getApp().globalData.choosenLine
			this.inmarkers = [];
			this.inpolyline = [];
			if(this.noFirst)
			this.setMarkers()
			this.noFirst = true
		},
		mounted() {
			this.outlocation()
			this.deviceInfo=wx.getDeviceInfo()
		}
	}
</script>

<style>
	.center {
		position: absolute;
		width: 50px;
		height: 100px;
		left: 50%;
		top: 50%;
		margin-left: -25px;
		margin-top: -100px;
		z-index: 999;
	}

	.center1 {
		position: absolute;
		width: 50px;
		height: 50px;
		left: 50%;
		top: 50%;
		margin-left: -25px;
		margin-top: -50px;
		z-index: 999;
	}
</style>